Skip to content

[TRTLLM-8489][feat] Support stream interval for Responses API - #10109

Closed
JunyiXu-nv wants to merge 1 commit into
NVIDIA:mainfrom
JunyiXu-nv:dev-junyi-support-stream-interval
Closed

JunyiXu-nv wants to merge 1 commit into
NVIDIA:mainfrom
JunyiXu-nv:dev-junyi-support-stream-interval

Conversation

@JunyiXu-nv

@JunyiXu-nv JunyiXu-nv commented Dec 18, 2025 •

Copy link
Copy Markdown
Collaborator

Summary by CodeRabbit

  • Refactor
    • Updated streaming response handling architecture to improve token batch processing and message formatting.
    • Reorganized internal streaming logic for reasoning and text delta emission to provide more consistent response sequencing.
    • Enhanced final content emission handling for both streaming and non-streaming response paths.

Description

Waiting for #9908.

Test Coverage

PR Checklist

Please review the following before submitting your PR:

  • PR description clearly explains what and why. If using CodeRabbit's summary, please make sure it makes sense.

  • PR Follows TRT-LLM CODING GUIDELINES to the best of your knowledge.

  • Test cases are provided for new code paths (see test instructions)

  • Any new dependencies have been scanned for license and vulnerabilities

  • CODEOWNERS updated if ownership changes

  • Documentation updated as needed

  • Update tava architecture diagram if there is a significant design change in PR.

  • The reviewers assigned automatically/manually are appropriate for the PR.

  • Please check this after reviewing the above items as appropriate for this PR.

GitHub Bot Help

/bot [-h] ['run', 'kill', 'skip', 'reuse-pipeline'] ...

Provide a user friendly way for developers to interact with a Jenkins server.

Run /bot [-h|--help] to print this help message.

See details below for each supported subcommand.

Details

run [--reuse-test (optional)pipeline-id --disable-fail-fast --skip-test --stage-list "A10-PyTorch-1, xxx" --gpu-type "A30, H100_PCIe" --test-backend "pytorch, cpp" --add-multi-gpu-test --only-multi-gpu-test --disable-multi-gpu-test --post-merge --extra-stage "H100_PCIe-TensorRT-Post-Merge-1, xxx" --detailed-log --debug(experimental)]

Launch build/test pipelines. All previously running jobs will be killed.

--reuse-test (optional)pipeline-id (OPTIONAL) : Allow the new pipeline to reuse build artifacts and skip successful test stages from a specified pipeline or the last pipeline if no pipeline-id is indicated. If the Git commit ID has changed, this option will be always ignored. The DEFAULT behavior of the bot is to reuse build artifacts and successful test results from the last pipeline.

--disable-reuse-test (OPTIONAL) : Explicitly prevent the pipeline from reusing build artifacts and skipping successful test stages from a previous pipeline. Ensure that all builds and tests are run regardless of previous successes.

--disable-fail-fast (OPTIONAL) : Disable fail fast on build/tests/infra failures.

--skip-test (OPTIONAL) : Skip all test stages, but still run build stages, package stages and sanity check stages. Note: Does NOT update GitHub check status.

--stage-list "A10-PyTorch-1, xxx" (OPTIONAL) : Only run the specified test stages. Examples: "A10-PyTorch-1, xxx". Note: Does NOT update GitHub check status.

--gpu-type "A30, H100_PCIe" (OPTIONAL) : Only run the test stages on the specified GPU types. Examples: "A30, H100_PCIe". Note: Does NOT update GitHub check status.

--test-backend "pytorch, cpp" (OPTIONAL) : Skip test stages which don't match the specified backends. Only support [pytorch, cpp, tensorrt, triton]. Examples: "pytorch, cpp" (does not run test stages with tensorrt or triton backend). Note: Does NOT update GitHub pipeline status.

--only-multi-gpu-test (OPTIONAL) : Only run the multi-GPU tests. Note: Does NOT update GitHub check status.

--disable-multi-gpu-test (OPTIONAL) : Disable the multi-GPU tests. Note: Does NOT update GitHub check status.

--add-multi-gpu-test (OPTIONAL) : Force run the multi-GPU tests in addition to running L0 pre-merge pipeline.

--post-merge (OPTIONAL) : Run the L0 post-merge pipeline instead of the ordinary L0 pre-merge pipeline.

--extra-stage "H100_PCIe-TensorRT-Post-Merge-1, xxx" (OPTIONAL) : Run the ordinary L0 pre-merge pipeline and specified test stages. Examples: --extra-stage "H100_PCIe-TensorRT-Post-Merge-1, xxx".

--detailed-log (OPTIONAL) : Enable flushing out all logs to the Jenkins console. This will significantly increase the log volume and may slow down the job.

--debug (OPTIONAL) : Experimental feature. Enable access to the CI container for debugging purpose. Note: Specify exactly one stage in the stage-list parameter to access the appropriate container environment. Note: Does NOT update GitHub check status.

For guidance on mapping tests to stage names, see docs/source/reference/ci-overview.md
and the scripts/test_to_stage_mapping.py helper.

kill

kill

Kill all running builds associated with pull request.

skip

skip --comment COMMENT

Skip testing for latest commit on pull request. --comment "Reason for skipping build/test" is required. IMPORTANT NOTE: This is dangerous since lack of user care and validation can cause top of tree to break.

reuse-pipeline

reuse-pipeline

Reuse a previous pipeline to validate current commit. This action will also kill all currently running builds associated with the pull request. IMPORTANT NOTE: This is dangerous since lack of user care and validation can cause top of tree to break.

@JunyiXu-nv
JunyiXu-nv force-pushed the dev-junyi-support-stream-interval branch from 38fda8b to f3663d9 Compare January 5, 2026 04:24
Signed-off-by: Junyi Xu <219237550+JunyiXu-nv@users.noreply.github.com>
@JunyiXu-nv
JunyiXu-nv force-pushed the dev-junyi-support-stream-interval branch from f3663d9 to b0c20c4 Compare February 23, 2026 04:29
@JunyiXu-nv

Copy link
Copy Markdown
Collaborator Author

/bot run

@JunyiXu-nv
JunyiXu-nv marked this pull request as ready for review February 23, 2026 05:19
@JunyiXu-nv
JunyiXu-nv requested a review from a team as a code owner February 23, 2026 05:19
@JunyiXu-nv
JunyiXu-nv requested a review from hchings February 23, 2026 05:19
@coderabbitai

coderabbitai Bot commented Feb 23, 2026

Copy link
Copy Markdown
Contributor
📝 Walkthrough

Walkthrough

This pull request modifies streaming response handling in the Harmony adapter and response utilities. Method signatures are updated to return tuples including a contents dictionary alongside messages. Streaming delta emission logic is refactored to handle reasoning deltas, text deltas, and final content separately with improved state management across Harmony and non-Harmony paths.

Changes

Cohort / File(s) Summary
Harmony Adapter Response Types
tensorrt_llm/serve/harmony_adapter.py
Updated process_token_batch_to_messages and stateful_stream_harmony_tokens_to_openai_messages to return tuples of (list[Message], dict[str, str]) instead of just messages. Modified handle_streaming_response and handle_non_streaming_response to unpack and forward the contents dictionary from adapter calls.
Streaming Delta Emission Logic
tensorrt_llm/serve/responses_utils.py
Refactored delta emission to handle reasoning_delta_text, delta_text, and final content as separate streaming events with new state flags (is_text_sent, is_reasoning_sent, is_output_item_added_sent). Updated both Harmony and non-Harmony streaming paths to emit output items and content parts in explicit sequences before pushing final text deltas.

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~25 minutes

🚥 Pre-merge checks | ✅ 1 | ❌ 2

❌ Failed checks (2 warnings)

Check name Status Explanation Resolution
Description check ⚠️ Warning The PR description is largely incomplete. It contains only a reference to a blocking PR (9908) and generic template content, with no actual explanation of the changes, implementation details, or test coverage. Provide a clear description of what stream interval support entails, why it was needed, which files were modified, and what tests validate these changes.
Docstring Coverage ⚠️ Warning Docstring coverage is 71.43% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (1 passed)
Check name Status Explanation
Title check ✅ Passed The title accurately describes the main feature being added: stream interval support for the Responses API, as evidenced by the code changes handling streaming deltas and content intervals.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
  • 📝 Generate docstrings (stacked PR)
  • 📝 Generate docstrings (commit on current branch)
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Post copyable unit tests in a comment

Tip

Issue Planner is now in beta. Read the docs and try it out! Share your feedback on Discord.


Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 1

Caution

Some comments are outside the diff and can’t be posted inline due to platform limitations.

⚠️ Outside diff range comments (1)
tensorrt_llm/serve/harmony_adapter.py (1)

148-191: ⚠️ Potential issue | 🔴 Critical

Critical: content deltas are accumulated before parser.process(token), producing off-by-one shifted output.

In the existing process_token_batch method (line 141), last_content_delta is read after self.parser.process(token). In process_token_batch_to_messages, the contents accumulation at lines 162-164 reads self.parser.last_content_delta before self.parser.process(token). This creates a timing mismatch:

  1. Each iteration appends the delta from the previous token, not the current one.
  2. The delta from the last token in every batch is never included in that batch's contents.
  3. The first iteration may capture a stale delta from the parser's previous state.

Move the content accumulation block after self.parser.process(token) to match the pattern in process_token_batch and ensure each token's delta is correctly captured in the current batch.

🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@tensorrt_llm/serve/harmony_adapter.py` around lines 148 - 191,
process_token_batch_to_messages has the content accumulation happening before
calling self.parser.process(token), causing off-by-one deltas; move the block
that reads/updates contents using self.parser.last_content_delta so it runs
after self.parser.process(token) (same pattern as process_token_batch) to ensure
each token's delta is captured for the current token and the final token's delta
isn't dropped; keep the existing logic that initializes
contents[self.parser.current_channel] and reading
self.parser.current_channel/current_recipient but perform those reads after
processing the token.
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.

Inline comments:
In `@tensorrt_llm/serve/responses_utils.py`:
- Around line 1559-1567: The code currently yields a reasoning/text delta event
even when the delta is whitespace-only, which can emit a delta before the
corresponding output-item-added/content-part-added events; update the logic in
the block handling reasoning_delta_text (and the analogous block for delta_text)
so that the yield of
streaming_events_helper.get_reasoning_text_delta_event(reasoning_delta_text)
(and streaming_events_helper.get_text_delta_event(delta_text)) is only executed
after you have emitted the added events — either by moving the delta yield
inside the if reasoning_delta_text.strip() branch or by forcing
streaming_events_helper.get_reasoning_output_added_events()/get_output_added_events()
to run whenever a delta is truthy; ensure you reference the existing helpers
(streaming_events_helper.is_reasoning_sent, get_reasoning_output_added_events,
get_reasoning_text_delta_event, get_output_added_events, get_text_delta_event)
when making the change.

---

Outside diff comments:
In `@tensorrt_llm/serve/harmony_adapter.py`:
- Around line 148-191: process_token_batch_to_messages has the content
accumulation happening before calling self.parser.process(token), causing
off-by-one deltas; move the block that reads/updates contents using
self.parser.last_content_delta so it runs after self.parser.process(token) (same
pattern as process_token_batch) to ensure each token's delta is captured for the
current token and the final token's delta isn't dropped; keep the existing logic
that initializes contents[self.parser.current_channel] and reading
self.parser.current_channel/current_recipient but perform those reads after
processing the token.

Comment on lines +1559 to +1567
# Reasoning delta may exist with text delta
if reasoning_delta_text:
if reasoning_delta_text.strip():
if not streaming_events_helper.is_reasoning_sent:
streaming_events_helper.is_reasoning_sent = True
yield from streaming_events_helper.get_reasoning_output_added_events(
)
yield streaming_events_helper.get_reasoning_text_delta_event(
reasoning_delta_text)

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ Potential issue | 🟠 Major

Reasoning delta emitted before output-item-added when text is whitespace-only.

If reasoning_delta_text is truthy but contains only whitespace (e.g. " "), the strip() check on Line 1561 is falsy so the output-item-added / content-part-added events are skipped, yet the reasoning text delta event on Line 1566 is still yielded. This violates the Responses API streaming protocol, which expects response.output_item.added and response.content_part.added to precede any delta event for that item.

The same pattern exists for delta_text on Lines 1588-1593.

Proposed fix: gate the delta yield behind the added-events guard, or always send added events when any delta is emitted
     # Reasoning delta may exist with text delta
     if reasoning_delta_text:
-        if reasoning_delta_text.strip():
-            if not streaming_events_helper.is_reasoning_sent:
-                streaming_events_helper.is_reasoning_sent = True
-            yield from streaming_events_helper.get_reasoning_output_added_events(
-            )
+        if not streaming_events_helper.is_reasoning_sent:
+            streaming_events_helper.is_reasoning_sent = True
+        yield from streaming_events_helper.get_reasoning_output_added_events()
         yield streaming_events_helper.get_reasoning_text_delta_event(
             reasoning_delta_text)
 
     # ...
 
     # Send delta events for ongoing content
     if delta_text:
-        if delta_text.strip():
-            if not streaming_events_helper.is_text_sent:
-                streaming_events_helper.is_text_sent = True
-            yield from streaming_events_helper.get_message_output_added_events()
+        if not streaming_events_helper.is_text_sent:
+            streaming_events_helper.is_text_sent = True
+        yield from streaming_events_helper.get_message_output_added_events()
         yield streaming_events_helper.get_text_delta_event(delta_text, [])

Alternatively, if there is a deliberate reason to skip whitespace-only leading deltas, move the delta yield inside the if .strip(): block as well.

🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@tensorrt_llm/serve/responses_utils.py` around lines 1559 - 1567, The code
currently yields a reasoning/text delta event even when the delta is
whitespace-only, which can emit a delta before the corresponding
output-item-added/content-part-added events; update the logic in the block
handling reasoning_delta_text (and the analogous block for delta_text) so that
the yield of
streaming_events_helper.get_reasoning_text_delta_event(reasoning_delta_text)
(and streaming_events_helper.get_text_delta_event(delta_text)) is only executed
after you have emitted the added events — either by moving the delta yield
inside the if reasoning_delta_text.strip() branch or by forcing
streaming_events_helper.get_reasoning_output_added_events()/get_output_added_events()
to run whenever a delta is truthy; ensure you reference the existing helpers
(streaming_events_helper.is_reasoning_sent, get_reasoning_output_added_events,
get_reasoning_text_delta_event, get_output_added_events, get_text_delta_event)
when making the change.

@tensorrt-cicd

Copy link
Copy Markdown
Collaborator

PR_Github #36454 [ run ] triggered by Bot. Commit: b0c20c4 Link to invocation

@tensorrt-cicd

Copy link
Copy Markdown
Collaborator

PR_Github #36454 [ run ] completed with state SUCCESS. Commit: b0c20c4
/LLM/main/L0_MergeRequest_PR pipeline #28201 completed with status: 'FAILURE'

⚠️ Action Required:

  • Please check the failed tests and fix your PR
  • If you cannot view the failures, ask the CI triggerer to share details
  • Once fixed, request an NVIDIA team member to trigger CI again

Link to invocation

@JunyiXu-nv

Copy link
Copy Markdown
Collaborator Author

/bot run

@tensorrt-cicd

Copy link
Copy Markdown
Collaborator

PR_Github #36620 [ run ] triggered by Bot. Commit: b0c20c4 Link to invocation

@tensorrt-cicd

Copy link
Copy Markdown
Collaborator

PR_Github #36620 [ run ] completed with state SUCCESS. Commit: b0c20c4
/LLM/main/L0_MergeRequest_PR pipeline #28342 completed with status: 'FAILURE'

⚠️ Action Required:

  • Please check the failed tests and fix your PR
  • If you cannot view the failures, ask the CI triggerer to share details
  • Once fixed, request an NVIDIA team member to trigger CI again

Link to invocation

@brnguyen2

Copy link
Copy Markdown
Collaborator

👋 As part of an effort to reduce the TensorRT-LLM open-PR backlog, we're checking in on PRs with no activity in over 120 days. This one qualifies.

Could you let us know whether you still plan to land it?

  • If yes: please rebase onto the latest main, resolve any merge conflicts, and re-request review (or just leave a comment with where it stands).
  • If it's no longer needed: you can close it, or let us know and we'll close it for you.

If we don't hear back within 14 days, we'll close this PR to keep the review queue manageable. Closing isn't a rejection: the branch, commits, and discussion are all preserved, and you can reopen or resubmit at any time.

Thanks for the contribution!

@brnguyen2

brnguyen2 commented Aug 28, 2026 •

Copy link
Copy Markdown
Collaborator

👋 Closing this as part of the TensorRT-LLM open-PR backlog cleanup. We pinged on 2026-08-10 about 120+ days of inactivity and didn't hear back within the 14-day window.

This isn't a rejection — your branch, commits, and discussion are all preserved. If it's still relevant, just reopen the PR any time and we'll pick it back up; please rebase onto the latest main when you do. Thanks again for the contribution!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants